package com.winit.schedule.core.repository.entity;

import java.io.Serializable;

import org.springframework.util.StringUtils;

import com.winit.schedule.core.model.TaskID;
import com.winit.schedule.core.repository.constants.TaskItemStatus;
import com.winit.schedule.core.utils.Clock;

public class TaskRunRecordEntity implements Serializable {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 9060510531090473357L;

    private String            taskTrackerUuid;                        // 运行任务的TaskTrackerUUID

    private String            taskRunnerUuid;                         // 任务运行器uuid

    private TaskID            taskId;                                 // 任务ID

    private String            taskItem;                               // 任务项参数

    private long              runStartTime;                           // 运行开始时间

    private long              runEndTime;                             // 运行结束时间

    private long              lastStatusUpdateTime;

    private long              lastFetchDataTime;                      // 最后一次抓取数据的时间

    private long              fetchDataNum;                           // 读取的数据量

    private long              fetchDataCount;                         // 读取次数

    private long              dealDataSucess;                         // 处理成功的数据量或调用成功次数

    private long              dealDataFail;                           // 处理失败的数据量或调用失败次数

    private long              dealSpendTime;                          // 处理总耗时,没有做同步，可能存在一定的误差

    private int               threadNum;                              // 处理任务的线程数

    private TaskItemStatus    taskItemStatus;                         // 任务处理的状态

    public TaskRunRecordEntity(){

    }

    public TaskRunRecordEntity(TaskRunnerEntity taskRunner, TaskItemStatus itemStatus){
        this(taskRunner, 0, itemStatus);
    }

    public TaskRunRecordEntity(TaskRunnerEntity taskRunner, long endTime, TaskItemStatus itemStatus){

        this.taskTrackerUuid = taskRunner.getTaskTrackerUuid();
        this.taskRunnerUuid = taskRunner.getTaskRunnerUuid();
        this.taskId = taskRunner.getTaskId();
        this.taskItem = StringUtils.collectionToCommaDelimitedString(taskRunner.getTaskItemIds());
        //this.taskItem = StringUtils.replace(this.taskItem, this.getTaskId().getId()+ "$", "");
        this.runStartTime = taskRunner.getRegisterTime();
        this.runEndTime = endTime;
        this.lastStatusUpdateTime = Clock.getSystemTime();
        this.lastFetchDataTime = taskRunner.getLastFetchDataTime();
        this.fetchDataNum = taskRunner.getFetchDataNum();
        this.fetchDataCount = taskRunner.getFetchDataCount();
        this.dealDataSucess = taskRunner.getDealDataSucess();
        this.dealDataFail = taskRunner.getDealDataFail();
        this.dealSpendTime = taskRunner.getDealSpendTime();
        this.threadNum = taskRunner.getThreadNum();
        this.taskItemStatus = itemStatus;
    }

    public String getTaskTrackerUuid() {
        return taskTrackerUuid;
    }

    public void setTaskTrackerUuid(String taskTrackerUuid) {
        this.taskTrackerUuid = taskTrackerUuid;
    }

    public String getTaskRunnerUuid() {
        return taskRunnerUuid;
    }

    public void setTaskRunnerUuid(String taskRunnerUuid) {
        this.taskRunnerUuid = taskRunnerUuid;
    }

    public TaskID getTaskId() {
        return taskId;
    }

    public void setTaskId(TaskID taskId) {
        this.taskId = taskId;
    }

    public String getTaskItem() {
        return taskItem;
    }

    public void setTaskItem(String taskItem) {
        this.taskItem = taskItem;
    }

    public long getRunStartTime() {
        return runStartTime;
    }

    public void setRunStartTime(long runStartTime) {
        this.runStartTime = runStartTime;
    }

    public long getRunEndTime() {
        return runEndTime;
    }

    public void setRunEndTime(long runEndTime) {
        this.runEndTime = runEndTime;
    }

    public long getLastFetchDataTime() {
        return lastFetchDataTime;
    }

    public void setLastFetchDataTime(long lastFetchDataTime) {
        this.lastFetchDataTime = lastFetchDataTime;
    }

    public long getFetchDataNum() {
        return fetchDataNum;
    }

    public void setFetchDataNum(long fetchDataNum) {
        this.fetchDataNum = fetchDataNum;
    }

    public long getFetchDataCount() {
        return fetchDataCount;
    }

    public void setFetchDataCount(long fetchDataCount) {
        this.fetchDataCount = fetchDataCount;
    }

    public long getDealDataSucess() {
        return dealDataSucess;
    }

    public void setDealDataSucess(long dealDataSucess) {
        this.dealDataSucess = dealDataSucess;
    }

    public long getDealDataFail() {
        return dealDataFail;
    }

    public void setDealDataFail(long dealDataFail) {
        this.dealDataFail = dealDataFail;
    }

    public long getDealSpendTime() {
        return dealSpendTime;
    }

    public void setDealSpendTime(long dealSpendTime) {
        this.dealSpendTime = dealSpendTime;
    }

    public int getThreadNum() {
        return threadNum;
    }

    public void setThreadNum(int threadNum) {
        this.threadNum = threadNum;
    }

    public TaskItemStatus getTaskItemStatus() {
        return taskItemStatus;
    }

    public void setTaskItemStatus(TaskItemStatus taskItemStatus) {
        this.taskItemStatus = taskItemStatus;
    }

    public long getLastStatusUpdateTime() {
        return lastStatusUpdateTime;
    }

    public void setLastStatusUpdateTime(long lastStatusUpdateTime) {
        this.lastStatusUpdateTime = lastStatusUpdateTime;
    }

}
